<?php

namespace App\Console\Commands;

use App\Companent\rndChinaName;
use App\Models\Entity;
use App\Models\PoliceStation;
use App\Models\PoliceStationHasSchool;
use App\Models\Student;
use Illuminate\Console\Command;

class StudentAdd extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'student:rand {school} {num}';
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */


    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $school_id = $this->argument('school');
        $name_obj = new rndChinaName();
        $num = $this->argument('num');
//        dd($name_obj->getName(2));
        //
        if(!$school_id){
            echo "请输入学校的ID"; die;
        }
        $police_station=PoliceStationHasSchool::query()->where('school_id',$school_id)->first();
        if(!$police_station){
            echo "该学校不在分片内"; die;
        }
        $section = PoliceStation::query()->where('id',$police_station->police_station_id)->first();
        for ($i = 0;$i<$num;$i++){
            $entity = new Entity();
            $entity->father_name=$name_obj->getName(2);
            $entity->father_id_code = $this->getIdCard();
            $entity->father_phone_number = mt_rand(13100000000,15100000000);
            $entity->mother_name = $name_obj->getName(2);
            $entity->mother_id_code = $this->getIdCard();
            $entity->mother_phone_number = mt_rand(13100000000,15100000000);
            $entity->family_address = '暂无';
            $entity->father_works = '崇光科技';
            $entity->mother_works = '崇光科技';
            $entity->save();
            $student = new Student();
            $student->name = $name_obj->getName(2);
            $student->school_id = $school_id;
            $student->police_station_id =$police_station->police_station_id;
            $student->nation = "汉族";
            $student->sex = 0;
            $student->twins = 1;
            $student->entity_id =$entity->id;
            $student->id_code = $this->getIdCard();
            $student->relation = "父子";
            $student->prophylactic_code = mt_rand(10000000000,11111111111);
            $student->section_id = $section->section_id;
            $student->is_twins = 0;
            $student->first_kid = 1;
            $student->save();
        }
    }
    public function getIdCard(){
        $mt_rand = mt_rand(100,20*3600*24*360);
        return '120'.mt_rand(101,106).date('Ymd',time()-$mt_rand).mt_rand(1,9999);
    }
}
